package com.tianji.aigc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/embedding")
public class EmbeddingController {
    @Autowired
    private VectorStore vectorStore;


    @Autowired
    private EmbeddingModel embeddingModel;


    @PostMapping
    public void saveVectorStore(@RequestParam("messages")List<String> messageList){
        //将字符串消息转为文档消息
        List<Document> documentList = messageList.stream().map(m -> Document.builder().text(m).build()).toList();
        vectorStore.add(documentList);

        log.info("向量数据库添加数据完毕，添加了{}条数据",messageList.size());
    }



}
